//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#define __NO_LINKNODE_CONSTRUCTOR

#include <core.h>
#include <_hal.h>
#include <_schedule.h>

//
// IdleScheduleClass
//
void IdleScheduleClass::Initialize()
{
}

void IdleScheduleClass::InitializeThread(Thread *pThread)
{
    assert(pThread);
    assert(pThread->m_pScheduleClass == this);

    pThread->m_bInherit = FALSE;

    pThread->m_pEffectiveScheduleClass = pThread->m_pScheduleClass;
}

void IdleScheduleClass::SetThreadPriority(
    Thread *pThread, ThreadPriority priority, bool_t bRunning)
{
    assert(pThread);
    assert(pThread->m_pScheduleClass == this);
    assert(ThreadPriority_Lowest <= priority
            && priority <= ThreadPriority_Highest);
}

ThreadPriority IdleScheduleClass::GetThreadPriority(Thread *pThread)
{
    assert(pThread);
    assert(pThread->m_pScheduleClass == this);
    return ThreadPriority_Lowest;
}

void IdleScheduleClass::OnThreadSleep(Thread *pThread)
{
    assert(pThread);
    assert(pThread->m_pEffectiveScheduleClass == this);
}

void IdleScheduleClass::OnThreadWakeUp(Thread *pThread)
{
    assert(pThread);
    assert(pThread->m_pEffectiveScheduleClass == this);
}

void IdleScheduleClass::OnThreadYield(Thread *pThread)
{
    assert(pThread);
    assert(pThread->m_pEffectiveScheduleClass == this);
}

void IdleScheduleClass::OnThreadSwitchOut(Thread *pThread)
{
    assert(pThread);
    assert(pThread->m_pEffectiveScheduleClass == this);
}

void IdleScheduleClass::EnterRunningList(
    Thread *pThread, RunningReason reason)
{
    assert(pThread);

    m_listHead.InsertLast(pThread);
}

void IdleScheduleClass::LeaveRunningList(Thread *pThread)
{
    assert(pThread);
    assert(pThread->m_pEffectiveScheduleClass == this);

    pThread->Detach();
}

void IdleScheduleClass::UpdateTime(uint_t uTicks)
{
    m_uElapsedTicks += uTicks;
}

bool_t IdleScheduleClass::UpdateThreadTime(
    Thread *pThread, uint_t uTicks)
{
    assert(pThread);
    assert(pThread->m_pEffectiveScheduleClass == this);

    return FALSE;
}

Thread *IdleScheduleClass::SelectNextThread()
{
    assert(!m_listHead.IsEmpty());
    return (Thread *)m_listHead.First();
}

IdleScheduleClass::IdleScheduleClass()
{
    m_type = ScheduleClassType_Idle;

    m_uElapsedTicks = 0;
    m_listHead.Initialize();
}

IdleScheduleClass g_idleScheduleClass;
